<?php
namespace Home\Controller;

class PersonalController extends CommonController{
    
    public function index(){
        //个人信息
        $User = M('User');$Hospital = M('Hospital');
        $userInfo = $User->find($this->uid);
        $this->assign('userInfo',$userInfo);
        //关联医生
        if($userInfo['uid']) $this->assign('docRow',$User->find($userInfo['uid']));
        //所属透析中心
        $this->assign('htpRow',$Hospital->find($userInfo['hpt_id']));
        //所属市下的医院列表
        $this->assign('hptArr',$Hospital->where(array('cid'=>$userInfo['city_id']))->select());
        $this->display();
    }
    
    public function editUserInfo(){
        if(I('post.name') && I('post.val'))
            M('User')->save(array('id'=>$this->uid,I('post.name')=>I('post.val')));
    }
    
    //积分使用情况
    public function score(){
        $this->assign('userInfo',M('User')->find($this->uid));
        //积分记录
        $p = I('request.p') ? intval(I('request.p')) : 1;
        $list = M('Score')->where(array('uid'=>$this->uid))->order('id desc')->page($p,10)->select();
        
        $scoreType = C('SCORETYPE');//积分类别数组
        foreach($list as $k=>$v){
            $list[$k]['type'] = $v['type'] == 'no' ? $v['reason'] : $scoreType[$v['type']];
            if($v['score'] > 0) $list[$k]['score'] = '+'.$v['score'];
        }
        
        if($p == 1){
            $this->assign('list',$list);
            $this->display();
        }else{//无限加载
            if(empty($list)){
                echo json_encode('err');die;
            }else{
                echo json_encode($list);die;
            }
        }
    }
    
    public function rule(){
        $userInfo = M('User')->find($this->uid);
        if($userInfo['type']=='1'){
            $this->display('Personal_ruledoc');
        }elseif($userInfo['type']=='2'){
            $this->display('Personal_rulepat');
        }else{
            $this->display('Personal_rulen');
        }
    }
    
}